package mmc.networking;

import mmc.action.Action;
import mmc.action.TargetException;
import mmc.server.RemoteClient;

@SuppressWarnings("serial")
public class UseAction extends Message {
	String className;
	int target;
	
	public UseAction(String name, int target)
	{
		className = name;
		this.target = target;
	}
	
	public void executeOnServer(RemoteClient context){
		Action a;
		
		try {
			a = (Action)Class.forName(className).newInstance();
		} catch (Exception e){
			throw new RuntimeException(e);
		}
		
		try {
			a.performOnServer(context, target);
		} catch (TargetException e) {
			e.printStackTrace();
			// TODO send error message to client instead of server console dump
		}
	}
}
